package com.cookor.poi.modules.phy.mobile;

import com.cookor.poi.common.beanvalidator.BeanValidators;
import com.cookor.poi.common.utils.ResultUtil;
import com.cookor.poi.common.utils.StringUtils;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Validator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

public class ApiBaseController {
  @Autowired
  protected Validator validator;
  
  protected Logger logger = LoggerFactory.getLogger(getClass());
  
  protected void beanValidator(Object object, Class<?>... groups) {
    BeanValidators.validateWithException(this.validator, object, groups);
  }
  
  public static ResultUtil getResult() {
    return new ResultUtil(ResultUtil.SUCCESS_CODE);
  }
  
  public static Integer getTenantId(HttpServletRequest request) throws Exception {
    String tenantId = request.getParameter("siteid");
    if (StringUtils.isBlank(tenantId))
      throw new Exception("机构id异常"); 
    return Integer.valueOf(tenantId);
  }
}
